# @FileName  :  signup.py
# @Time      :  2025/7/28 22:34
# @Author    :  Ayanami
# @info      :  报名相关的Pydantic模型

from datetime import datetime
from typing import Optional, List
from pydantic import BaseModel, Field


class SignUpBase(BaseModel):
    """报名基础模型"""
    start_date: datetime = Field(..., description="报名开始时间")
    end_date: datetime = Field(..., description="报名结束时间")
    max_capacity: int = Field(..., gt=0, description="最大报名人数")
    course_id: int = Field(..., description="课程ID")


class SignUpCreate(SignUpBase):
    """创建报名模型"""
    pass


class SignUpUpdate(BaseModel):
    """更新报名模型"""
    start_date: Optional[datetime] = Field(None, description="报名开始时间")
    end_date: Optional[datetime] = Field(None, description="报名结束时间")
    max_capacity: Optional[int] = Field(None, gt=0, description="最大报名人数")
    course_id: Optional[int] = Field(None, description="课程ID")


class SignUpResponse(SignUpBase):
    """报名响应模型"""
    id: int
    created_at: datetime
    updated_at: datetime
    current_enrollment_count: int = Field(default=0, description="当前报名人数")

    class Config:
        from_attributes = True


class EnrollmentRecordBase(BaseModel):
    """报名记录基础模型"""
    signup_id: int = Field(..., description="报名表ID")
    student_id: int = Field(..., description="学员ID")


class EnrollmentRecordCreate(EnrollmentRecordBase):
    """创建报名记录模型"""
    pass


class EnrollmentRecordResponse(EnrollmentRecordBase):
    """报名记录响应模型"""
    id: int
    signup_time: datetime

    class Config:
        from_attributes = True


class SignUpWithDetailsResponse(SignUpResponse):
    """包含详细信息的报名响应模型"""
    course_title: str = Field(..., description="课程名称")
    teacher_name: str = Field(..., description="讲师姓名")
    agent_name: str = Field(..., description="培训机构名称")
    enrollments: List[EnrollmentRecordResponse] = Field(
        default_factory=list,
        description="报名记录列表"
    )

class EnrollmentRecordWithDetailsResponse(EnrollmentRecordResponse):
    """包含详细信息的报名记录响应模型"""
    student_name: str = Field(..., description="学员姓名")
    student_phone: str = Field(..., description="学员手机号")
    course_title: str = Field(..., description="课程名称")
    signup_start_date: datetime = Field(..., description="报名开始时间")
    signup_end_date: datetime = Field(..., description="报名结束时间")


class PaginatedSignUpResponse(BaseModel):
    """分页报名响应模型"""
    items: List[SignUpWithDetailsResponse]
    total: int
    page: int
    page_size: int
    has_next: bool
    has_prev: bool


class PaginatedEnrollmentResponse(BaseModel):
    """分页报名记录响应模型"""
    items: List[EnrollmentRecordWithDetailsResponse]
    total: int
    page: int
    page_size: int
    has_next: bool
    has_prev: bool